package com.jhhc.Config;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

@Configuration
@MapperScan(value = {"com.jhhc.WaterQuality.BaseInfo.dao","com.jhhc.WaterQuality.Calculate.Forecast.dao"
,"com.jhhc.EngineeringSafety.BaseInfo.dao","com.jhhc.EngineeringSafety.Calculate.Forecast.dao"}, sqlSessionFactoryRef = "sqlSessionFactory7")
public class WqAndEsConfig {

    @Autowired
    @Qualifier("wqDataSource")
    private DataSource ds7;

    @Bean(name = "sqlSessionFactory7")
    @Primary
    public SqlSessionFactory sqlSessionFactory7() throws Exception {
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        sqlSessionFactoryBean.setDataSource(ds7);
        return sqlSessionFactoryBean.getObject();
    }

    @Bean
    @Primary
    public SqlSessionTemplate sqlSessionTemplate7() throws Exception {
        return new SqlSessionTemplate(sqlSessionFactory7());
    }
}
